<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>节流防抖</title>
</head>

<body>
  <!-- 

    1. 节流指在规定时间内只执行一次
    2. 防抖指在触发事件后n秒后才执行操作，如果在这n秒内再次触发了该事件，则重新计时
   -->

  <script>

    let flag = false

    function postSomething () {
      if (flag) return
      //do something
      flag = true
    }
  </script>
</body>

</html>